package dyyx.demo;

import java.util.Date;

import org.h2.mvstore.MVStore;

import dyyx.util.CommUtil;

public class MVStoreMultiOpenTest {

	public static void main(String[] args) throws Exception {
		System.out.println("hello,MVStoreMultiOpenTest," + new Date());

		String fileName = CommUtil.getUserHome() + "/h2/001.data";

		MVStore s = null;
		MVStore s2 = null;
		
		MVStore readOnlyStore = null;
		MVStore readOnlyStore2 = null;

		
		try {
			
			readOnlyStore = new MVStore.Builder().fileName(fileName).readOnly().open();
			System.out.println("readOnlyStore="+readOnlyStore);

			readOnlyStore2 = new MVStore.Builder().fileName(fileName).readOnly().open();
			System.out.println("readOnlyStore2="+readOnlyStore2);

			
		
			// java.lang.IllegalArgumentException: Directory does not exist:
			// nio:/Users/dugang/h2 [1.4.200/0]
			s = MVStore.open(fileName);
			System.out.println("s="+s);
			
			
			
			
			// java.lang.IllegalStateException: The file is locked:
			// nio:/Users/dugang/h2/001.data [1.4.200/7]
			// java.nio.channels.OverlappingFileLockException
			s2 = MVStore.open(fileName);
			
			System.out.println("s2="+s2);

			
		} finally {
			CommUtil.close(s2);
			CommUtil.close(s);
			CommUtil.close(readOnlyStore);
			CommUtil.close(readOnlyStore2);


		}

	}
}
